//
//  MainController.m
//  1243
//
//  Created by 我的 on 16/3/22.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "MainController.h"
#import "BaseNavController.h"
#import "HomeViewController.h"
#import "MeViewController.h"
#import "ShopViewController.h"
#import "gongNengBViewController.h"
#import "DianZhuanTableViewController.h"

@interface MainController ()

@property (nonatomic, strong) ShopViewController *gongnengA;

@end

@implementation MainController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    HomeViewController *home = [[HomeViewController alloc] init];
    [self addChildViewControllers:home andImage:[UIImage imageNamed:@"icon_1_n"] andSelectedImage:[UIImage imageNamed:@"icon_1_h"] andTitle:@"首页"];
    
    ShopViewController *gongnengA = [[ShopViewController alloc] init];
    [self addChildViewControllers:gongnengA andImage:[UIImage imageNamed:@"icon_2_n"] andSelectedImage:[UIImage imageNamed:@"icon_2_h"] andTitle:@"商城"];
    self.gongnengA = gongnengA;
    
    DianZhuanTableViewController *dianzhuan = [[DianZhuanTableViewController alloc] init];
    [self addChildViewControllers:dianzhuan andImage:[UIImage imageNamed:@"icon_3_n"] andSelectedImage:[UIImage imageNamed:@"icon_3_h"] andTitle:@"点赚"];
    
    gongNengBViewController *gongnengB = [[gongNengBViewController alloc] init];
    [self addChildViewControllers:gongnengB andImage:[UIImage imageNamed:@"icon_4_n"] andSelectedImage:[UIImage imageNamed:@"icon_4_h"] andTitle:@"附近商家"];
    
    MeViewController *me = [[MeViewController alloc] init];
    [self addChildViewControllers:me andImage:[UIImage imageNamed:@"icon_5_n"] andSelectedImage:[UIImage imageNamed:@"icon_5_h"] andTitle:@"会员中心"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeIndex) name:@"DidClickButtonChangeTabBarControllerSelected" object:
     nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didClickChangeTabBarController) name:@"DidClickXiaoFeiButtonChangeTabBarControllerSelected" object:nil];
    
    
    
    
}

- (void)changeIndex {
    self.selectedViewController = [self.viewControllers objectAtIndex:1];
}

- (void)didClickChangeTabBarController {
    [self changeIndex];
}

- (void)addChildViewControllers:(UIViewController *)viewController andImage:(UIImage *)image andSelectedImage:(UIImage *)selectedImage andTitle:(NSString *)controllerName {
    
    BaseNavController *baseController = [[BaseNavController alloc] initWithRootViewController:viewController];
    
    viewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    viewController.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    viewController.title = controllerName;
    
//    [self.tabBarController addChildViewController:baseController];
    
    [self addChildViewController:baseController];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
